<?php

/*
 * C 端 controller 父类
 */

namespace Think;

use Think\Controller;

class C_Controller extends Controller {

    public function __construct() {
        parent::__construct();
        import('Memcachectr');
        $this->m = \Think\Memcachectr::create();
        import('Sessions');
        new Sessions();
        $sid = trim($_GET['session_id']);
        if(strlen($sid) == 32){
            $this->session_id = $sid;
        }else{
            $this->session_id = session_id();
        }
        
    }

    /**
     * 解决微信session存取问题
     */
    public function setSession($arr = false) { }

    public function getSession() { }
    
    public function shopList(){
        $store_id = trim($_GET['store_id']);
        $map_logic = new \Home\Logic\CompanystoremapLogic();
        $store_map = $map_logic->getStoreByNumber($store_id);
        if(count($store_map)>0){
            $store_logic = new \Home\Logic\StoreLogic();
            $stores = array();
            foreach($store_map as $v){
                $stores[] = $v['store_id'];
            }
            $stores = $store_logic->getStoresByIds($stores);
            $this->assign('stores',$stores);
            $this->assign('logo',$stores[0]['logo']);
            $base_url = explode('?', $_SERVER['REQUEST_URI']);
            $this->assign('base_url',$base_url[0]);
            layout('shoplist');
            $this->display('shoplist');
            exit;
        }else{
            if($store_map[0]['store_id']<1){
                throw new \Exception();
            }
            $_GET['store_id'] = $store_map[0]['store_id'];
            $this->store_id = $store_map[0]['store_id'];
        }
    }

}
